package com.accp.restaurant.service;

import com.accp.restaurant.entity.Room;
import org.springframework.stereotype.Service;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.util.List;

@Service
public class ReserveService {

    @PersistenceContext
    private EntityManager entityManager;

    public List<Room> query(Integer tabinput) {
        if (tabinput == 1) {
            String jpql = "select r from Room r join fetch r.roomtype where 1=1   and r.roomtype.roomtypeid between 4 and 6";
            Query query = entityManager.createQuery(jpql);
            return query.getResultList();
        } else if (tabinput == 2) {
            String jpql = "select r from Room r join fetch r.roomtype where 1=1  and r.roomtype.roomtypeid between 1 and 3";
            Query query = entityManager.createQuery(jpql);
            return query.getResultList();
        }
        return null;
    }


}
